// pages/refund/refund.js
const feedbackApi = require('../common/showToast.js');
const getToken = require('../../utils/get_token.js');
let cookie, token,md,openId,tuanId;
const remaind = (that) => {
  let params = ['shop/order/tipShip', {"memberId": md ,"orderSn":id }]
  getToken.getData(function (res) {
    console.log(res.data)
    feedbackApi.showToast({ title: '已提醒商家尽快发货', mask: false })//调用 showToast
  }, ...params)
};
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
      reson:'点击选择退款原因',
      orderSn:'',
      spShow:false,
      intRealPrice:'0.01',
      Index:-1,
      alist:
           [{'name':'与卖家协商一致','value':0,'checked':false},
            {'name':'缺货','value':1,'checked':false},
            {'name':'未按时发货','value':2,'checked':false},
            {'name':'不想要/错拍','value':3,'checked':false},
            {'name':'其他','value':4,'checked':false}],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    that.data.orderSn = options.id;
    that.data.intRealPrice = options.price;
    tuanId=options.tuanId;
    md = wx.getStorageSync('memberId') || '';
    openId = wx.getStorageSync('openId') || '';
    cookie = wx.getStorageSync('cookie') || '';
    token = wx.getStorageSync('token') || '';
     that.setData({
      intRealPrice:that.data.intRealPrice
     })

  },
  openp:function(){
    this.setData({
      spShow:true
    })
  },
  radioChange(e) {//单选框
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    this.data.Index=Number(e.detail.value);
    const alist = this.data.alist;
    for (let i = 0, len = alist.length; i < len; ++i) {
      if(alist[i].value==e.detail.value)
      {
        alist[i].checked=true;
      }else{
        alist[i].checked=false;
      }
    }
    this.setData({
      alist
    })
  },
  sure:function(){
    let that=this;
    let index=that.data.Index;
    that.data.reson=index>=0?that.data.alist[index].name:that.data.reson;
    that.setData({
      reson:that.data.reson,
      spShow:false
    })
  },
  submitRefund:function(e){//提交申请
    console.log(e.detail.value);
    let that=this;
    if(e.detail.value.textarea=='')
    {
      feedbackApi.showToast({ title: '请输入申请原因', mask: false })//调用 showToast
      return;
    }
    if(that.data.Index<0)
    {
      feedbackApi.showToast({ title: '请选择退款原因', mask: false })//调用 showToast
      return;
    }
    let messaing=encodeURIComponent(e.detail.value.textarea);
    let params = ['shop/order/applyForRefundn', {"A":that.data.orderSn,"B":md,"C":messaing,"D":"","E":that.data.Index+1}]
      getToken.getData(function (res) {
        console.log(res.data)
        if(!res.data.flag)
        {
          Com.message(data.message);
        }else{
          wx.redirectTo({
            url: `../rdt/rdt?orderSn=${that.data.orderSn}&tuanId=${tuanId}`,
          })
        } 
      }, ...params)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})